import vm from "@/main.js";

// const getHandledValue = num => {
//   return num < 10 ? '0' + num : num
// }
// const getWeek = (date) => {
//   var week;
//   if (date.getDay() == 0) week = "日"
//   if (date.getDay() == 1) week = "一"
//   if (date.getDay() == 2) week = "二"
//   if (date.getDay() == 3) week = "三"
//   if (date.getDay() == 4) week = "四"
//   if (date.getDay() == 5) week = "五"
//   if (date.getDay() == 6) week = "六"
//   return week;
// }
// // 日期格式
// let TimeDate = function (timestamp, number) {
//   if (!timestamp) {
//     return "--"
//   } else {
//     let timestamp1;
//     String(timestamp).length == 13 ? timestamp1 = Number(timestamp) : timestamp1 = Number(timestamp) * 1000;
//     const dateObj = new Date(+timestamp1); // ps, 必须是数字类型，不能是字符串, +运算符把字符串转化为数字，更兼容
//     const year = dateObj.getFullYear(); // 获取年，
//     const month = getHandledValue(dateObj.getMonth() + 1); // 获取月，必须要加1，因为月份是从0开始计算的
//     const date = getHandledValue(dateObj.getDate()); // 获取日，记得区分getDay()方法是获取星期几的。
//     const hours = getHandledValue(dateObj.getHours());
//     const minutes = getHandledValue(dateObj.getMinutes()); // 获取分
//     const seconds = getHandledValue(dateObj.getSeconds()); // 获取秒

//     if (number == '1') {
//       return year + '年' + month + '月' + date + '日星期' + getWeek(dateObj)
//     } else if (number == '2') {
//       return hours + ':' + minutes
//     } else if (number == '3') {
//       return year + '-' + month + '-' + date
//     } else if (number == '4') {
//       return "周" + getWeek(dateObj)
//     } else if (number == '5') {
//       return year + '年' + month + '月'
//     } else if (number == '6') {
//       return hours + ':' + minutes + ':' + seconds
//     } else {
//       return year + '-' + month + '-' + date + '\n' + hours + ':' + minutes + ':' + seconds
//     }
//   }
// }

//小数位数固定 (四舍五入)
let Fixed = function (value, number) {
  if (value == 0) {
    return 0
  }
  if (value) {
    return Number(value).toFixed(number)
  } else {
    return "--"
  }
}

// 获取el-tag  标签类型
let getTagType = function (val) {
  if (val == 1) {
    return "primary"
  } else if (val == 2) {
    return "success"
  } else if (val == 3) {
    return "warning"
  } else if (val == 4) {
    return "danger"
  } else if (val == 5) {
    return "info"
  }
}


let release = function (val, list, key, reutrnKey) {
  //var back= list.find(item=> item.id == 1)
  // back.val
  key = key || 'id';
  reutrnKey = reutrnKey || 'value' 
  val = String(val)
  if (!val) {
    return ''
  }
  if ([','].includes(val)) {
    return '、'
  }
  var filter = list.find(item => String(item[key]) == String(val));
  if (filter) {
    if(reutrnKey=='obj'){
      return filter
    }else{
      return filter[reutrnKey];
    }
  } else {
    return '--'
  }
}
export {
  Fixed,
  getTagType,
  release,
}
